package com.warmup.model;
import java.util.Objects;

/**
 * 学生实体类
 */
public class Student {
    private final String studentId; // 学号，设为final，一旦创建不可更改
    private String name;          // 姓名
    private int age;              // 年龄

    public Student(String studentId, String name, int age) {
        this.studentId = studentId;
        this.name = name;
        this.age = age;
    }

    // --- Getter 和 Setter ---
    public String getStudentId() {
        return studentId;
    }

    public String getName() {
        return this.name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return this.age;
    }

    public void setAge(int age) {
        this.age = age;
    }


    /**
     * 重写toString()方法，返回清晰的学生信息格式
     */
    @Override
    public String toString() {
        return "学号: " + this.studentId + ", 姓名: " + this.name + ", 年龄: " + this.age;
    }

    /**
     * 重写equals()方法，仅通过学号判断对象是否相等
     */
    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Student student = (Student) o;
        return Objects.equals(this.studentId, student.studentId);
    }

    /**
     * 重写hashCode()方法，仅基于学号生成哈希码（与equals逻辑一致）
     */
    @Override
    public int hashCode() {
        return Objects.hash(this.studentId);
    }
}
